package com.jyh.autoconfiguration;

import com.jyh.entity.JyhProperties;
import com.jyh.service.JyhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author JYH
 * @version 1.0
 * @date 2022/11/17 15:48
 */
@Configuration//标记该类为配置类
@EnableConfigurationProperties(JyhProperties.class)//开启属性配置
@ConditionalOnClass(JyhService.class)//只有JyhService被引入后，当前得类才会创建
@ConditionalOnProperty(prefix = "spring.jyh", value = "enabled", matchIfMissing = true) //如果引用者没有给定相关得属性值，则采用默认值
public class JyhAutoConfiguration {

    @Autowired
    private JyhProperties jyhProperties;

    @Bean
    @ConditionalOnMissingBean
    public JyhService jyhService(){
        return new JyhService(jyhProperties);
    }

}
